package com.zhihesj.anan.system.controller;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhihesj.anan.message.Message;
import com.zhihesj.anan.system.entity.Logininfor;
import com.zhihesj.anan.system.service.LogininforService;
import com.zhihesj.anan.system.vo.LogininforVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 系统访问记录 前端控制器
 * </p>
 *
 * @author anan
 * @since 2020-07-30
 */
@RestController
@RequestMapping("/system/logininfor")
public class LogininforController {

    @Autowired
    private LogininforService logininforService;

    @GetMapping("/getLogininforList")
    public Message getLogininforList(LogininforVo logininforVo){
        System.out.println(logininforVo);
        Map<String, Object> stringObjectMap = BeanUtil.beanToMap(logininforVo, false, true);
        QueryWrapper<Logininfor> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("login_time");
        if (stringObjectMap.isEmpty()) {
            List<Logininfor> logininfors = logininforService.list(wrapper);
            return Message.success(logininfors);
        } else {
            List<Logininfor> logininfors = logininforService.list(wrapper);
            return Message.success(logininfors);
        }
    }
}
